package com.autumn.platform.dao.schema.script.original;

import java.util.List;

import org.apache.ibatis.parsing.XNode;
import org.apache.ibatis.scripting.xmltags.ForEachSqlNode;
import org.apache.ibatis.scripting.xmltags.MixedSqlNode;
import org.apache.ibatis.scripting.xmltags.SqlNode;
import org.apache.ibatis.session.Configuration;

import com.autumn.platform.dao.schema.script.ScriptHandlerSupport;

public class ForEachScriptHandler extends ScriptHandlerSupport {

    @Override
    public void handleScriptNode(Configuration configuration, XNode node, List<SqlNode> targetContents) {
        List<SqlNode> contents = parseDynamicTags(configuration, node);
        MixedSqlNode mixedSqlNode = new MixedSqlNode(contents);
        String collection = node.getStringAttribute("collection");
        String item = node.getStringAttribute("item");
        String index = node.getStringAttribute("index");
        String open = node.getStringAttribute("open");
        String close = node.getStringAttribute("close");
        String separator = node.getStringAttribute("separator");
        ForEachSqlNode forEachSqlNode = new ForEachSqlNode(configuration, mixedSqlNode, collection, index, item,
                open, close, separator);
        targetContents.add(forEachSqlNode);
    }
}
